package dk.dtu.android.gui;

import dk.dtu.android.transport.R;
import dk.dtu.android.transport.SendSMS;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;

public class OrderActivity extends Activity {
    Button order;
    EditText zone;
    EditText noZones;
    ToggleButton btn1990;
    ToggleButton btn1415;
	
    String phoneNo = "";
    
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_order);
        
        order = (Button) findViewById(R.id.btnOrder);
        zone = (EditText) findViewById(R.id.editText1);
        noZones = (EditText) findViewById(R.id.editText2);
        btn1990 = (ToggleButton) findViewById(R.id.toggleButton4);
        btn1415 = (ToggleButton) findViewById(R.id.toggleButton5);
        
        btn1990.setOnClickListener( new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				btn1415.setChecked(false);
				
			}
		});
        
        btn1415.setOnClickListener( new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				btn1990.setChecked(false);
				
			}
		});

        
        order.setOnClickListener(new View.OnClickListener() {
        	@Override
			public void onClick(View v) {
				if(btn1990.isChecked()) {
					phoneNo = "1990";
					sendSMS(phoneNo);
				}
				else if(btn1415.isChecked()) {
					phoneNo = "1415";
					sendSMS(phoneNo);
				}
				else
					Toast.makeText(getBaseContext(), 
							"You need to select a phone number",
							Toast.LENGTH_SHORT).show();
			}
		});
    }
	
	public void sendSMS(String phoneNo) {
		String txtZone = zone.getText().toString();
		String txtNumber = noZones.getText().toString();
		if (txtZone.length() > 0 && txtNumber.length() > 0) {
			SendSMS.SMS(phoneNo, txtZone, txtNumber);
			Toast.makeText(getBaseContext(), 
					"SMS Sent!",
					Toast.LENGTH_SHORT).show();
		} else {
			Toast.makeText(getBaseContext(), 
					"Must enter which zone you are in, and how many zones you need",
					Toast.LENGTH_LONG).show();
		}	
	}
}
